﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using OAProject.Domain.Entities;
using OAProject.Domain.Interfaces;
using OAProject.Infrastructure.Data;

/// <summary>
/// 实现nlog接口
/// </summary>
namespace OAProject.API
{
    public class NLogRepository : DapperRepository<LogMessage>,INLogRepository
    {
        //依赖注入
        public IConfiguration _configuration;

        public NLogRepository(IConfiguration configuration)
        {
            this._configuration = configuration;
            //连接字符串
            this.ConnStr = _configuration.GetConnectionString("ConnStr");
            SimpleCRUD.SetDialect(SimpleCRUD.Dialect.MySQL);
            Conn = new MySql.Data.MySqlClient.MySqlConnection(this.ConnStr);
        }



        /// <summary>
        /// 批量删除日志状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Upt(string id)
        {
            string sql = $"update LogMessage set State= 0 where  LogId in ({id})";
            return Conn.Execute(sql);
        }

        /// <summary>
        /// 还原日志状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int UptTrue(string id)
        {
            string sql = $"update LogMessage set State= 1 where  LogId in ({id})";
            return Conn.Execute(sql);
        }
        
    }
}
